<script setup lang="ts">
import officeApi from "@/api/office/officeApi";
import EditorJS from '@editorjs/editorjs'

const text = ref({});

const props = defineProps(["officeId"]);

// const container = ref();
const docValue = ref("");

const queryData = async () => {
	let data = await officeApi.getContentByOfficeId({
		officeId: props.officeId
	})

	if (!data) {
		data = {};
	}
	if (!data.content) {
		return '';
	}
	return JSON.parse(data.content);
}
const initWork = async () => {
	const data = await queryData();
	console.log(data)
	text.value = data;
	// workbook = univer.createUnit(UniverCore.UniverInstanceType.UNIVER_DOC, data)
}

let editor = null;

onMounted(async () => {
	await initWork();

	editor = new EditorJS({
		holderId: 'editorjs',
		data: text.value
	})

})


const getValue = async () => {
	// console.log(workbook)
	// const saveData = workbook.save();
	// const c = wordEditor.value.getValue();
	// return c;
	const data = await editor.save()
	console.log(data)
	return data;
	// return saveData;
}

defineExpose({
	getValue
})

</script>

<template>
	<div id="editorjs"></div>
</template>

<style scoped></style>
